package com.tdd;

import static org.junit.Assert.assertEquals;

import java.math.BigDecimal;

import org.junit.Before;
import org.junit.Test;

public class PrimeFactorsTest {
	HpStack stack;

	@Before
	public void init() {
		stack = new HpStack();
	}

	@Test
	public void primeFactorsOf2Are2() {
		givenAnOperandOf(2);
		whenCalculatingItsPrimeFactors();
		thenTheResultShouldInclude(2);
	}

	@Test
	public void primeFactorsOf1IsNothing() {
		givenAnOperandOf(1);
		whenCalculatingItsPrimeFactors();
		theResultShouldBeEmpty();
	}

	private void theResultShouldBeEmpty() {
		assertEquals(0, stack.size());
	}

	private void thenTheResultShouldInclude(Integer expected) {
		assertEquals(expected, stack.pop());
	}

	private void whenCalculatingItsPrimeFactors() {
		new PrimeFactors().operate(stack);
	}

	private void givenAnOperandOf(Integer value) {
		stack.push(new BigDecimal(value));
	}
}
